package inet.app.view.adapter;

import inet.app.R;
import inet.app.model.object.KqGiai_Item;

import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class KetQuaMbAdapter extends ArrayAdapter<KqGiai_Item> {

	private ArrayList<KqGiai_Item> items;
	private Activity context;
	private String giaidb,giai1;
	private String[] giai2,giai3,giai4,giai5,giai6,giai7;
	public KetQuaMbAdapter(Context context, ArrayList<KqGiai_Item> items) {
		super(context, R.layout.list_item_kqmb,items);
		this.items = items;
		this.context = (Activity) context;
	}
	
	public KetQuaMbAdapter(Context context, ArrayList<KqGiai_Item> items,ArrayList<String> item,ArrayList<String> path) {
		super(context, R.layout.list_item_kqmb,items);
		
		this.items = items;
		this.context = (Activity) context;
	}
	
	static class ViewHolder {
		protected TextView tvTitle;
		protected TextView tvGiaiDb,tvGiai1;
		protected TextView tvGiai2_1,tvGiai2_2;
		protected TextView tvGiai3_1,tvGiai3_2,tvGiai3_3,tvGiai3_4,tvGiai3_5,tvGiai3_6;
		protected TextView tvGiai4_1,tvGiai4_2,tvGiai4_3,tvGiai4_4;
		protected TextView tvGiai5_1,tvGiai5_2,tvGiai5_3,tvGiai5_4,tvGiai5_5,tvGiai5_6;
		protected TextView tvGiai6_1,tvGiai6_2,tvGiai6_3;
		protected TextView tvGiai7_1,tvGiai7_2,tvGiai7_3,tvGiai7_4;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = null;
		if (convertView == null) {
			LayoutInflater inflater = context.getLayoutInflater();
			v = inflater.inflate(R.layout.list_item_kqmb, null);
			final ViewHolder vh = new ViewHolder();
			vh.tvTitle = (TextView) v.findViewById(R.id.tvTitle);
			vh.tvGiaiDb = (TextView) v.findViewById(R.id.tvGiaiDb);
			vh.tvGiai1 = (TextView) v.findViewById(R.id.tvGiai1);
			vh.tvGiai2_1 = (TextView) v.findViewById(R.id.tvGiai2_1);
			vh.tvGiai2_2 = (TextView) v.findViewById(R.id.tvGiai2_2);
			
			vh.tvGiai3_1 = (TextView) v.findViewById(R.id.tvGiai3_1);
			vh.tvGiai3_2 = (TextView) v.findViewById(R.id.tvGiai3_2);
			vh.tvGiai3_3 = (TextView) v.findViewById(R.id.tvGiai3_3);
			vh.tvGiai3_4 = (TextView) v.findViewById(R.id.tvGiai3_4);
			vh.tvGiai3_5 = (TextView) v.findViewById(R.id.tvGiai3_5);
			vh.tvGiai3_6 = (TextView) v.findViewById(R.id.tvGiai3_6);
			
			vh.tvGiai4_1 = (TextView) v.findViewById(R.id.tvGiai4_1);
			vh.tvGiai4_2 = (TextView) v.findViewById(R.id.tvGiai4_2);
			vh.tvGiai4_3 = (TextView) v.findViewById(R.id.tvGiai4_3);
			vh.tvGiai4_4 = (TextView) v.findViewById(R.id.tvGiai4_4);
			
			vh.tvGiai5_1 = (TextView) v.findViewById(R.id.tvGiai5_1);
			vh.tvGiai5_2 = (TextView) v.findViewById(R.id.tvGiai5_2);
			vh.tvGiai5_3 = (TextView) v.findViewById(R.id.tvGiai5_3);
			vh.tvGiai5_4 = (TextView) v.findViewById(R.id.tvGiai5_4);
			vh.tvGiai5_5 = (TextView) v.findViewById(R.id.tvGiai5_5);
			vh.tvGiai5_6 = (TextView) v.findViewById(R.id.tvGiai5_6);
			
			vh.tvGiai6_1 = (TextView) v.findViewById(R.id.tvGiai6_1);
			vh.tvGiai6_2 = (TextView) v.findViewById(R.id.tvGiai6_2);
			vh.tvGiai6_3 = (TextView) v.findViewById(R.id.tvGiai6_3);
			
			vh.tvGiai7_1 = (TextView) v.findViewById(R.id.tvGiai7_1);
			vh.tvGiai7_2 = (TextView) v.findViewById(R.id.tvGiai7_2);
			vh.tvGiai7_3 = (TextView) v.findViewById(R.id.tvGiai7_3);
			vh.tvGiai7_4 = (TextView) v.findViewById(R.id.tvGiai7_4);
			
			v.setTag(vh);
		} else {
			v = convertView;
		}
		
		ViewHolder holder = (ViewHolder) v.getTag();
		giaidb=items.get(position).getGiaidb();
		giai1 =items.get(position).getGiai1();
		giai2= items.get(position).getGiai2().split("-");
		giai3= items.get(position).getGiai3().split("-");
		giai4= items.get(position).getGiai4().split("-");
		giai5= items.get(position).getGiai5().split("-");
		giai6= items.get(position).getGiai6().split("-");
		giai7= items.get(position).getGiai7().split("-");
		
		holder.tvTitle.setText("Kết Quả Xổ Số "+items.get(position).getName()+ " - " + items.get(position).getDate());
		holder.tvGiaiDb.setText(giaidb);
		holder.tvGiai1.setText(giai1);
		holder.tvGiai2_1.setText(giai2[0]);
		holder.tvGiai2_2.setText(giai2[1]);
		
		holder.tvGiai3_1.setText(giai3[0]);
		holder.tvGiai3_2.setText(giai3[1]);
		holder.tvGiai3_3.setText(giai3[2]);
		holder.tvGiai3_4.setText(giai3[3]);
		holder.tvGiai3_5.setText(giai3[4]);
		holder.tvGiai3_6.setText(giai3[5]);
		
		holder.tvGiai4_1.setText(giai4[0]);
		holder.tvGiai4_2.setText(giai4[1]);
		holder.tvGiai4_3.setText(giai4[2]);
		holder.tvGiai4_4.setText(giai4[3]);

		holder.tvGiai5_1.setText(giai5[0]);
		holder.tvGiai5_2.setText(giai5[1]);
		holder.tvGiai5_3.setText(giai5[2]);
		holder.tvGiai5_4.setText(giai5[3]);
		holder.tvGiai5_5.setText(giai5[4]);
		holder.tvGiai5_6.setText(giai5[5]);
		
		holder.tvGiai6_1.setText(giai6[0]);
		holder.tvGiai6_2.setText(giai6[1]);
		holder.tvGiai6_3.setText(giai6[2]);
		
		holder.tvGiai7_1.setText(giai7[0]);
		holder.tvGiai7_2.setText(giai7[1]);
		holder.tvGiai7_3.setText(giai7[2]);
		holder.tvGiai7_4.setText(giai7[3]);
		
		return v;
	}

}
